@extends('layouts.back_stage')
@section('style')
    @parent
    <link rel="stylesheet" href="{{env('CDN_DOMAIN_NAME')}}/css/dateSelect.css"/>
@endsection
@section('script')
    @parent
    <script src="{{env('CDN_DOMAIN_NAME')}}/js/dateSelect.js"></script>
@endsection
@section('content')
    <style>
        .form-control{font-size:12px;}
        .postage_money{border:1px solid #ccc;}
    </style>
    <div class="container">
        <div style="padding:20px 20px 20px 0;overflow:hidden;">
            <h3 style="float:left;">邮费录入</h3>
        </div>
        <form action="" role="form">
            <label>运单号：</label><input type="text"  placeholder="请输入运单号" class="form-control waybill" style="width: 200px;display: inline-block;" value="{{ $data['user_num'] }}" name="user_num">
            <label>时间：</label><input id="date1" class="form-control start_time" style="width:120px;display: inline-block;background:#fff;" name="start_at" type="text" value="{{ $data['start_at'] }}" readonly placeholder="开始时间" />
            <input id="date2" class="form-control end_time"  name="end_at" style="width:120px;display: inline-block;background:#fff;" type="text" value="{{ $data['end_at'] }}" readonly placeholder="结束时间" />
            <button type="submit" class="btn btn-info" id="sort_btn" style="margin-bottom:4px;">搜索</button>
        </form>
        <table class="table table-hover" style="margin-top: 20px;">
            <thead>
            <tr>
                <th >运单号</th>
                <th>发货时间</th>
                <th>预收邮费</th>
                <th>实际邮费</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>
            @if(isset($express) && count($express) > 0)
                @foreach($express as $k=>$v)
                <tr class="tr_{{ $v->id }}" abc="{{ $v->id }}">
                    <td>{{ $v->express_num }}</td>
                    <td>{{ $v->created_at }}</td>
                    <td>{{ sprintf('%.2f',$v->total_postage) }}</td>
                    <td class="td_money"><input type="text" class="postage_money" value="{{ sprintf('%.2f',$v->actual_postage) }}" disabled="disabled" onkeyup="clearNoNum(this)"></td>
                    <td class="td_postage"><a class="postage_a" href="javascript:;">录入</a></td>
                </tr>
               @endforeach
            @endif
            </tbody>
        </table>
        <div style="float: right"><div style="float: right;margin:20px 0;"><button class="btn btn-info" onclick="returnPage()" style="float:right;">跳转</button><input type="text" class="form-control returnPage" style="width:6rem;float: right;margin:0 5px;"></div>{{$express->appends(['start_at'=>$data['start_at'],'end_at'=>$data['end_at'],'user_num'=>$data['user_num']])->links()}}</div>

    </div>
    <script>
        /*日期插件初始化*/
        $("#date1").dateSelect();
        $("#date2").dateSelect();
        $(document).on("click",".postage_a",function(){
            var id=$(this).parent(".td_postage").parent().attr("abc");
            $(".tr_"+id).children(".td_postage").empty();
            $(".tr_"+id).children(".td_postage").append("<a class='postage_sure' href='javascript:;'>确定</a>");
            $(".tr_"+id).children(".td_money").children(".postage_money").removeAttr("disabled","disabled");
        });
        $(document).on("click",".postage_sure",function(){
            var id=$(this).parent(".td_postage").parent().attr("abc");
            var price=$(this).parent(".td_postage").prev(".td_money").children(".postage_money").val();
            if( price < 5 ){
                $(".faceImg").attr("src","/img/weep.png");
                $(".oHandle").text("实际邮费不能小于5元");
                $(".oSuccess").show(0).delay(1000).hide(0);
                return false;
            }
            $(".tr_"+id).children(".td_postage").empty();
            $(".tr_"+id).children(".td_postage").append("<a class='postage_a' href='javascript:;'>录入</a>");
            $(".tr_"+id).children(".td_money").children(".postage_money").attr("disabled","disabled");
            $.ajax({
                headers: {'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')},
                url:'/finance/setActualPostagePrice',
                data:{'id':id,'price':price},
                type:'post',
                dataType: 'json',
                success:function (data) {
                    if(data.success) {

                    }else {
                        $(".faceImg").attr("src","/img/weep.png");
                        $(".oHandle").text(data.msg);
                        $(".oSuccess").show(0).delay(1000).hide(0);
                    }
                }
            })
        })
        /*价格*/
            function clearNoNum(obj){
                obj.value = obj.value.replace(/[^\d.]/g,"");
                obj.value = obj.value.replace(/\.{2,}/g,".");
                obj.value = obj.value.replace(/^\./g,"");
                obj.value = obj.value.replace(".","$#$").replace(/\./g,"").replace("$#$",".");
                obj.value = obj.value.replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3');
                if(obj.value.indexOf(".")< 0 && obj.value !=""){
                    obj.value= parseFloat(obj.value);
                }
            }
    </script>
@endsection